/*
 * AddProductCategoryFrame.java
 *
 * Created on __DATE__, __TIME__
 */

package tw.com.jinwei.ui;

import javax.swing.JOptionPane;

import org.apache.commons.lang.StringUtils;

import tw.com.jinwei.db.ProductCategory;
import tw.com.jinwei.service.ProductService;
import tw.com.jinwei.utils.Constants;
import tw.com.jinwei.utils.ContextUtils;

/**
 *
 * @author  __USER__
 */
public class AddProductCategoryFrame extends javax.swing.JInternalFrame {

	/** Creates new form AddProductCategoryFrame */
	public AddProductCategoryFrame() {
		super(Constants.TITLE_PRODUCT_CATEGORY_ADD, true, true, true, true);
		initComponents();
	}

	/** This method is called from within the constructor to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
	//GEN-BEGIN:initComponents
	// <editor-fold defaultstate="collapsed" desc="Generated Code">
	private void initComponents() {

		jLabel1 = new javax.swing.JLabel();
		jLabel2 = new javax.swing.JLabel();
		jTextField1 = new javax.swing.JTextField();
		jTextField2 = new javax.swing.JTextField();
		jButton1 = new javax.swing.JButton();

		jLabel1.setText("\u5546\u54c1\u7c21\u78bc");

		jLabel2.setText("\u5546\u54c1\u898f\u683c");

		jTextField1.setColumns(50);

		jTextField2.setColumns(50);

		jButton1.setText("\u78ba\u5b9a");
		jButton1.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jButton1ActionPerformed(evt);
			}
		});

		org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
				getContentPane());
		getContentPane().setLayout(layout);
		layout
				.setHorizontalGroup(layout
						.createParallelGroup(
								org.jdesktop.layout.GroupLayout.LEADING)
						.add(
								layout
										.createSequentialGroup()
										.addContainerGap()
										.add(
												layout
														.createParallelGroup(
																org.jdesktop.layout.GroupLayout.LEADING)
														.add(
																layout
																		.createSequentialGroup()
																		.add(
																				jLabel1)
																		.add(
																				18,
																				18,
																				18)
																		.add(
																				jTextField1,
																				org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
																				org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
																				org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
														.add(
																layout
																		.createSequentialGroup()
																		.add(
																				jLabel2)
																		.add(
																				18,
																				18,
																				18)
																		.add(
																				jTextField2,
																				org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
																				org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
																				org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
														.add(jButton1))
										.addContainerGap(460, Short.MAX_VALUE)));
		layout
				.setVerticalGroup(layout
						.createParallelGroup(
								org.jdesktop.layout.GroupLayout.LEADING)
						.add(
								layout
										.createSequentialGroup()
										.addContainerGap()
										.add(
												layout
														.createParallelGroup(
																org.jdesktop.layout.GroupLayout.BASELINE)
														.add(jLabel1)
														.add(
																jTextField1,
																org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
																org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
																org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
										.add(18, 18, 18)
										.add(
												layout
														.createParallelGroup(
																org.jdesktop.layout.GroupLayout.BASELINE)
														.add(jLabel2)
														.add(
																jTextField2,
																org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
																org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
																org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
										.add(18, 18, 18).add(jButton1)
										.addContainerGap(171, Short.MAX_VALUE)));

		pack();
	}// </editor-fold>
	//GEN-END:initComponents

	private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
		String shortcode = jTextField1.getText();
		String spec = jTextField2.getText();
		if (StringUtils.isEmpty(shortcode) || StringUtils.isEmpty(spec)) {
			JOptionPane.showMessageDialog(this, Constants.MSG_PRODUCT_CATEGORY_ERROR);
		} else {
			ProductCategory category = new ProductCategory();
			category.setShortcode(shortcode);
			category.setSpec(spec);
			ProductService service = (ProductService)ContextUtils.getContext().getBean("productServiceProxy");
			service.addCategory(category);
			jTextField1.setText("");
			jTextField2.setText("");
		}
	}

	//GEN-BEGIN:variables
	// Variables declaration - do not modify
	private javax.swing.JButton jButton1;
	private javax.swing.JLabel jLabel1;
	private javax.swing.JLabel jLabel2;
	private javax.swing.JTextField jTextField1;
	private javax.swing.JTextField jTextField2;
	// End of variables declaration//GEN-END:variables

}